#[macro_use]
extern crate derive_builder;

use clap::Parser;
use log::{debug, warn};

use crate::app::{Cli, Commands, APP_CONFIG};
use crate::services::{create_user, start_bsbot, NUMBERS};

mod app;
mod commands;
mod db;
mod services;
mod structs;

#[tokio::main]
async fn main() {
    pretty_env_logger::init();
    let cli = Cli::parse();
    {
        let mut d = APP_CONFIG.write().unwrap();
        *d = cli.clone().into();
    }
    match db::init_db() {
        Ok(_) => debug!("Ok"),
        Err(err) => warn!("Initial tables error {}", err),
    };
    match &cli.command {
        Commands::RunBot => start_bsbot().await,
        Commands::CreateUser(args) => create_user(args.name.clone()),
    }
}
